package com.tang.springbootinit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.events.Event;

@RestController
public class HelloSpringBoot {


    @Value("${name}")
    private String name;

    @Value("${person.name}")
    private String name1;

    @Value("${person.age}")
    private String age;

    @Value("${person2.age}")
    private String age2;

    @Value("${address[0]}")
    private String address1;

    @Value("${address[1]}")
    private String address2;

    //第二种方式获取yml中的的数据
    @Autowired
    private Environment environment;  //在springBoot启动时spring容器就会初始化好它

    //注入Person对象
    @Autowired
    private Person person;

    @RequestMapping("/ceshi1")
    public void ceshi(){
        System.out.println(name);
        System.out.println(name1);
        System.out.println(age);
        System.out.println(age2);
        System.out.println(address1);
        System.out.println(address2);
        System.out.println(environment.getProperty("name"));
        System.out.println(environment.getProperty("person2.age"));

        System.out.println(person);

    }

    @RequestMapping("/hello")
    public String hello(){
        return "hello springboot_web";
    }
}
